package com.niit.dao;

import com.niit.pojo.StudentTable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

/**
 * @author 杨铭
 * 2022/2/7,20:47
 */
public class updateStudent {
    Configuration conf;

    public updateStudent() {
        HbaseConnection hbaseConnection = new HbaseConnection();
        Configuration conf = hbaseConnection.connect();
        this.conf = conf;
    }

    public void update(StudentTable studentTable) throws IOException {
        HBaseAdmin admin = new HBaseAdmin(conf);
        System.out.println(studentTable.toString());
        HTable hTable = new HTable(conf, "Student_Table");
        Put put = new Put(Bytes.toBytes(studentTable.getStudentId()));   //ROW KEY
        put.add(Bytes.toBytes("info"), Bytes.toBytes("Name"), Bytes.toBytes(studentTable.getName()));
        put.add(Bytes.toBytes("info"), Bytes.toBytes("DateOfEnrollment"), Bytes.toBytes(studentTable.getDateOfEnrollment()));
        put.add(Bytes.toBytes("info"), Bytes.toBytes("ContactNumber"), Bytes.toBytes(studentTable.getContactNumber()));
        put.add(Bytes.toBytes("status"), Bytes.toBytes("StudentStatus"), Bytes.toBytes(studentTable.getStudentStatus()));
        hTable.put(put);
        hTable.close();
    }
}
